package com.huanyang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {

    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("juejin")
                .description("掘金社区")
                .contact(new Contact("韦欢洋", "地址", "huanyang@qq.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApi(ApiInfo apiInfo) {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.huanyang.article.controller")
                        .or(RequestHandlerSelectors.basePackage("com.huanyang.cms.controller"))
                        .or(RequestHandlerSelectors.basePackage("com.huanyang.tag.controller"))
                        .or(RequestHandlerSelectors.basePackage("com.huanyang.recommend.controller"))
                        .or(RequestHandlerSelectors.basePackage("com.huanyang.interact.controller"))
                        .or(RequestHandlerSelectors.basePackage("com.huanyang.passport.controller"))
                )
                .paths(PathSelectors.any())
                .build();
    }
}
